// pages/user/changeAddress/changeAddress.js
const handler = require("../../../utils/function.js");
var api = require("../../../api.js"),
    app = getApp();
Page({
    /**
     * 页面的初始数据
     */
    data: {
        img: handler.userImg,
        old_address: '',
        new_address: '',
        order_no: '',
        target_adds: '', //原来目的地
    },
    //获取修改后的地址
    newAddressInput: function(e) {
        var new_address = e.detail.value;
        const that = this;
        wx.chooseLocation({
            success: function(res) {
                console.log(res, '2222222222222222')
                // new_address_location:
                that.setData({
                    new_address: res.address,
                    loaction: {
                        lat: res.latitude,
                        lng: res.longitude
                    }
                })
                console.log(that.data.new_address)
            },
        })
    },
    //确认投诉
    getComplain: function() {
        var that = this;
        var {
            new_address
        } = that.data;
        var newlocation = JSON.stringify(that.data.loaction);
        var testNewAddress = handler.regTest(new_address, '请选择最终目的地');
        if (testNewAddress) {
            var that = this;
             var onum = that.data.order_no;
            app.request({
                url: api.order.change,
                method: 'post',
                data: {
                    order_no: that.data.order_no,
                    newaddress: that.data.new_address,
                    target_adds_location: newlocation,
                },
                success: function(rs) {
                    console.log('修改结果', rs)
                    if (rs.code == 1) {
                      wx.navigateBack({
                        url: "/pages/map/orderGoing/orderGoing?order_no=" + onum,
                      })
                        // wx.redirectTo({
                          
                        // })
                    }else{
                      wx.showToast({
                        title: '订单仅能修改一次',
                        icon:'none'
                      })
                    }
                }
            })
           
        } else {
            var testNewAddress = handler.regTest(new_address, '请选择最终目的地');
        }
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function(options) {
        console.log('员目的', options)
        this.setData({
            order_no: options.order_no,
            target_adds: options.target_adds
        })
      // 获取优惠券
      if (options.uid) {
        app.shareCouponsMessage(options.uid)
      }
    },
  // 用户分享
  onShareAppMessage: function () {
    let title = app.shareAppMessage().title;
    let imageUrl = app.shareAppMessage().imageUrl;
    let desc = app.shareAppMessage().desc;
    let path = app.shareAppMessage().path;
    // console.log(app.shareAppMessage())
    return {
      title: title,
      imageUrl: imageUrl,
      desc: desc,
      path: path,
    }
  },
})